package com.audaque.cloud.iqs.dbs.service;


import com.audaque.cloud.iqs.dbs.vo.ColumnInfo;
import com.audaque.cloud.iqs.dbs.vo.DateVo;
import com.audaque.cloud.iqs.dbs.vo.TableInfo;

import java.util.List;
import java.util.Map;

/**
 * sql组装
 * @author HuangHL
 * @date 2022-10-17 16:50:29
 */
public interface DsHandler {

    static DsHandler getInstance(String driveClass,List<DsHandler> dsHandlers){
        for (DsHandler dsHandler:dsHandlers) {
            if(dsHandler.canHander(driveClass)) {
                return dsHandler;
            }
        }
        return null;
    }

    /**
     * 匹配数据库类型
     * @param driveClass
     * @return
     */
    boolean canHander(String driveClass);

    /**
     * 获取表的sql
     * @param scheme
     * @param user
     * @return
     */
    String getTablesSql(String scheme,String user);

    /**
     * 获取字段的sql
     * @param scheme
     * @param user
     * @param tableName
     * @return
     */
    String getColumnsSql(String scheme,String user,String tableName);

    /**
     * 获取shceme
     * @return
     */
    String getSchema(String schema,String database,String username);

    /**
     * list变成表对象
     * @param list
     * @return
     */
    List<TableInfo> listToTables(List<Map<String, Object>> list);

    /**
     * list变成列对象
     * @param list
     * @return
     */
    List<ColumnInfo> listToColumns(List<Map<String, Object>> list, String tableName);

    /**
     * 分页sql
     * @param sql
     * @return
     */
    String getPage(String sql, int pageNo,int pageSize);

    /**
     * 替换日期处理sql
     * @param dateVo
     * @return
     */
    String getDateWhereSql(DateVo dateVo);

    /**
     * 处理as
     * @param sql
     * @return
     */
    String prosessAs(String sql);

    String sqlSpilit();
}
